package com.kgcx.order.rabbitmq;

import com.kgcx.common.eum.OrderEnum;
import com.kgcx.core.utils.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class ChangeDriverListener {

    private static final Logger LOG = LoggerFactory.getLogger(ChangeDriverListener.class);

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "kgcxChangeDriverQueue", errorHandler = "custRabbitListenerErrorHandler")
    public void changeDriver(String json)
    {
        LOG.info("订单-改派订单，json=" + json);

        HashMap<String, Object> changeJson = (HashMap<String, Object>) JsonUtil.toObject(json, Map.class);

        stringRedisTemplate.opsForList().remove(OrderEnum.ORDERS_DRIVER + "_IN_SERVICE_" + changeJson.get("driver_id"),1, changeJson.get("order_no"));
    }

}
